<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui/css/layui.css">
</head>
<body>
	<div class="layui-container layui-col-space15" style="margin: 20px auto; width: 100%;">
		
		<div class="layui-row">
			<div class="layui-col-md12">
				<div class="layui-card">
					<div class="layui-card-header">部门列表</div>
					<div class="layui-card-body">
						<div>
							<button class="layui-btn layui-btn-sm" onclick="openWin();">添加</button>
						</div>
						<table class="layui-table">
							<colgroup>
								<col width="5%">
							    <col width="10%">
								<col width="10%">
							    <col width="20%">
								<col width="20%">
								<col width="20%">
							    <col>
							</colgroup>
							  <thead>
							    <tr>
									<th>
										<input type="checkbox" />
									</th>
									<th>序号</th>
									<th>部门ID</th>
									<th>部门名称</th>
									<th>主管</th>
									<th>员工人数</th>
									<th>操作</th>
							    </tr> 
							  </thead>
							  <tbody>
							  	<c:forEach items="${list}" var="dept" varStatus="no">
								<tr>
									<td><input type="checkbox" /></td>
									<td>${no.index+1}</td>
									<td>${dept.id }</td>
									<td>${dept.deptName }</td>
									<td>${dept.leaderName }</td>
									<th>${dept.staffNum }</th>
									<td>
										<button class="layui-btn layui-btn-sm" onclick="openUpWin('${dept.id}');">更新</button>
										<button class="layui-btn layui-btn-sm" onclick="del('${dept.id}');">删除</button>
									</td>
							    </tr>
								</c:forEach>
							    
							  </tbody>
						</table>
					</div>
				</div>  
			</div>
		</div>
	</div>
</body>
<script src="${pageContext.request.contextPath}/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery-1.9.1.min.js"></script>
<script>
	//注册layer弹层组件
	layui.use(['layer'], function(){
		var layer = layui.layer;
	});
	
	function openWin(){		
		layer.open({
			type: 2,
			title: "添加部门",
			area: ['450px', '530px'],
			content: "dt?method=toAddPage"
		});
	}
	
	function openUpWin(deptId){		
		layer.open({
			type: 2,
			title: "更新部门",
			area: ['450px', '530px'],
			content: "dt?method=toUpPage&deptId="+deptId
		});
	}
	function del(id){
		if(confirm("确定删除吗？"))
		{
			$.ajax({
				url:"dt",
				data:{"method":"del","id":id},
				dataType:"text",
				type:"post",
				success:function(str){
					if(str == "1"){
						alert("删除成功");
						//刷新当前页面
						window.location.reload();
					} else {
						alert("删除失败");
					}	
				}
			});
		}
	}

</script>
</html>
